$(function() {
    // 搜索统计
    // 每日收藏数
    var collectionChart = echarts.init(document.getElementById("echarts-collection"));
    axios.get("http://127.0.0.1:8000/statistics/?field=collection").then(
        function(response) {
            var resp = response.data
            var date = resp['title_list']
            var data = resp['data_list']
            console.log(resp)
            collectionChart.setOption({
                title: {
                    text: ''
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['收藏数']
                },
                grid: {
                    x: 40,
                    x2: 40,
                    y2: 24
                },
                calculable: true,
                xAxis: [{
                    type: 'category',
                    boundaryGap: false,
                    data: date
                }],
                yAxis: [{
                    type: 'value',
                    axisLabel: {
                        formatter: '{value}'
                    }
                }],
                series: [{
                    name: '收藏数',
                    type: 'line',
                    data: data,
                    markPoint: {
                        data: [
                            { type: 'max', name: '最大值' },
                            { type: 'min', name: '最小值' }
                        ]
                    },
                    markLine: {
                        data: [
                            { type: 'average', name: '平均值' }
                        ]
                    }
                }, ]
            });

            $(window).resize(collectionChart.resize);
        },
        function(err) {
            console.log(err)
            $(window).resize(collectionChart.resize);
        }
    )

    // 总收藏数增长
    var collectionallChart = echarts.init(document.getElementById("echarts-collectionall"));
    axios.get("http://127.0.0.1:8000/statistics/?field=comment&type=add").then(
        function(response) {
            var resp = response.data
            var date = resp['title_list']
            var data = resp['data_list']
            console.log(resp)
            collectionallChart.setOption({
                title: {
                    text: ''
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['收藏数']
                },
                grid: {
                    x: 40,
                    x2: 40,
                    y2: 24
                },
                calculable: true,
                xAxis: [{
                    type: 'category',
                    boundaryGap: false,
                    data: date
                }],
                yAxis: [{
                    type: 'value',
                    axisLabel: {
                        formatter: '{value}'
                    }
                }],
                series: [{
                    name: '收藏数',
                    type: 'bar',
                    data: data,
                    markPoint: {
                        data: [
                            { type: 'max', name: '最大值' },
                            { type: 'min', name: '最小值' }
                        ]
                    }
                }, ]
            });

            $(window).resize(collectionallChart.resize);
        },
        function(err) {
            console.log(err)
            $(window).resize(collectionallChart.resize);
        }
    )
})